/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：PersonalMenuScreen.java <br>
 * 创建时间：2014-8-3 上午11:24:34 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.community;

import android.widget.Toast;

import java.util.ArrayList;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.listener.DeleteListener;
import cn.bmob.v3.listener.EmailVerifyListener;
import cn.bmob.v3.listener.UpdateListener;
import lostland.gmud.exv2.Game;
import lostland.gmud.exv2.Gmud;
import lostland.gmud.exv2.expand.GeneralMenuScreen;
import lostland.gmud.exv2.ui.LockedScreen;

/**
 * 类名：PersonalMenuScreen <br>
 * 说明：个人资料菜单
 *
 * @author 12548
 */
public class PersonalMenuScreen extends GeneralMenuScreen {

	/**
	 */
	public PersonalMenuScreen() {
		super(gets(), "请选择操作：");
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.ScrollableMenuScreen#onCancel()
	 */
	@Override
	public void onCancel() {
		getGame().popScreen();
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.ScrollableMenuScreen#onClick(int)
	 */
	@Override
	public void onClick(int i) {
		switch (i) {
//		case 0:
//			GmudUser user = GmudUser.getInstance();
//			
//			game.setScreen(new BigEventScreen(game,"个人资料",
//					"邮箱：" + user.getEmail() + 
//					"\n昵称：" + user.getNickName() + 
//					"\n社区金币：" + user.getGold(),
//					true, null));
//			break;
			case 0:

//			game.setScreen(new YesNoScreen(game,"更新绑定角色需要花费50社区金币，确定吗？") {
//
//				@Override
//				protected void onYes() {
				new LockedScreen("正在更新绑定角色……").pushToGame();
				BindingCharactor me = new BindingCharactor();
				me.setOwner(GmudUser.getInstance());
				me.setCharactor(Gmud.mc);
				me.newOrUpdate(new UpdateListener() {

					@Override
					public void onFailure(int arg0, String arg1) {
						Toast.makeText(Game.getInstance(), "绑定角色更新失败！" + arg1, Toast.LENGTH_SHORT).show();
						Game.getInstance().popScreen();
					}

					@Override
					public void onSuccess() {
//							GmudUser.getInstance().increment("gold", -50);
//							GmudUser.getInstance().update(game, new UpdateListener() {
//
//								@Override
//								public void onFailure(int arg0, String arg1) {
//								}
//
//								@Override
//								public void onSuccess() {
//								}});
						Toast.makeText(getGame(), "绑定角色更新成功！", Toast.LENGTH_SHORT).show();
						Game.getInstance().popScreen();
					}
				});
//				}
//
//				@Override
//				protected void onNo() {
//					game.setParentScreen();
//				}});
//			
				break;
//		case 1:
//			game.getHandler().obtainMessage(23).sendToTarget();
//			break;
			case 1:

				new LockedScreen("正在发送验证邮件").pushToGame();
				BmobUser.requestEmailVerify(getGame(), GmudUser.getInstance().getEmail(), new EmailVerifyListener() {

					@Override
					public void onFailure(int arg0, String arg1) {
						Toast.makeText(Game.getInstance(), "邮件发送失败！" + arg1, Toast.LENGTH_SHORT).show();
						Game.getInstance().popScreen();
					}

					@Override
					public void onSuccess() {
						Toast.makeText(Game.getInstance(), "邮件发送成功！请登陆" + GmudUser.getInstance().getEmail() + "进行验证", Toast.LENGTH_SHORT).show();
						Game.getInstance().popScreen();
					}
				});


				break;
			case 2:
				new LockedScreen("正在删除社区帐号").pushToGame();
				GmudUser.getInstance().delete(Game.getInstance(), new DeleteListener() {

					@Override
					public void onFailure(int arg0, String arg1) {
						Toast.makeText(Game.getInstance(), "失败！" + arg1, Toast.LENGTH_SHORT).show();
						Game.getInstance().popScreen();
					}

					@Override
					public void onSuccess() {
						Toast.makeText(Game.getInstance(), "社区帐号删除成功！", Toast.LENGTH_SHORT).show();
						GmudUser.getInstance();
						BmobUser.logOut(Game.getInstance());
						Game.getInstance().popToRootScreen();
					}
				});
				break;
		}
	}

	private static ArrayList<String> gets() {
		ArrayList<String> s = new ArrayList<>();
//		s.add("查看个人资料");
		s.add("绑定角色");
//		s.add("修改昵称");
		s.add("重发验证邮件");
		s.add("删除社区帐号");
		return s;
	}
}
